<script setup lang='ts'>
import { inject } from 'vue';
const realmoney = inject<number>('money', 0)//0是默认值
const costMoneyFunc = inject<(money: number) => void>('cost')
const cutMoney = () => {
  //要花爷爷的钱
  if (costMoneyFunc) {   //由于爷爷传递的函数可能不存在，所以要判断一下
    costMoneyFunc(9999)
  }
}
</script>
<template>
  <h3>我是孙子</h3>
  <p>得到爷爷给的零花钱：{{ realmoney }}</p>
  <button @click="cutMoney">买一台华为mate70</button>
</template>
<style scoped></style>